package com.pan.admin.generator.util;

import com.gitee.apanlh.util.base.CollUtils;
import com.gitee.apanlh.util.base.IteratorUtils;
import com.gitee.apanlh.util.base.StringUtils;
import com.hankcs.hanlp.dictionary.py.Pinyin;
import com.hankcs.hanlp.dictionary.py.PinyinDictionary;

import java.util.List;

/**
 *  API对接拼音工具类
 *
 *  @author Pan
 */
public class ApiGenHttpPinyinUtils {

    /**
     *  获取简写名称
     *
     *  @param  name
     *  @return String
     */
    public static String getCustomName(String name) {
        List<Pinyin> listPinyin = PinyinDictionary.convertToPinyin(name, true);
        CollUtils.filter(listPinyin, t -> t.getPinyinWithoutTone().contains("none"));

        StringBuilder sb = new StringBuilder();
        IteratorUtils.array(listPinyin, t -> sb.append(StringUtils.upperFirst(t.getPinyinWithoutTone())));
        return sb.toString();
    }
}
